package kdweibo4j;

import kdweibo4j.org.json.JSONException;
import kdweibo4j.org.json.JSONObject;

/**
 * 代表第三方微博的转过来的数据
 * 
 * @author goldenrod.zhu@gmail.com
 */
public class MsgExtra implements java.io.Serializable{
	private static final long serialVersionUID = 1L;
	public String appUrl;
	public String id;
	public String tenantId;
	public String type;
	public String refId;
	public Properties properties;
	
	public MsgExtra(JSONObject json) throws WeiboException{
		constructJson(json);
	}

	private void constructJson(JSONObject json) throws WeiboException {
		try {
			appUrl = json.optString("appUrl");
			id = json.optString("id");
			tenantId = json.optString("tenantId");
			type = json.optString("type");
			refId = json.optString("refId");
			if(!json.isNull("properties")){
				properties = new Properties(json.getJSONObject("properties"));
			}
		} catch (JSONException e) {
			throw new WeiboException(e.getMessage() + ":" + json.toString(),e);
		}
	}
	
	public class Properties implements java.io.Serializable {
		private static final long serialVersionUID = 1L;
		public String site;
		public String id;
		public String externalId;
		public String content;
		public String senderId;
		public String senderName;
		public String original;
		public String middle;
		public String thumbnail;
		public String forwardedSendTime;
		public String forwardedExternalId;
		public String forwardedId;
		public String forwardedSenderId;
		public String forwardedContent;
		public String forwardedSenderName;
		public String forwardedOriginal;
		public String forwardedMiddle;
		public String forwardedThumbnail;

		public Properties(JSONObject json) {
			site = json.optString("site");
			id = json.optString("id");
			externalId = json.optString("externalId");
			content = json.optString("content");			
			senderId = json.optString("senderId");		
			senderName = json.optString("senderName");
			original = json.optString("original");
			middle = json.optString("middle");
			thumbnail = json.optString("thumbnail");
			forwardedSenderId = json.optString("forwardedSenderId");
			forwardedContent = json.optString("forwardedContent");
			forwardedSenderName = json.optString("forwardedSenderName");
			forwardedId = json.optString("forwardedId");
			forwardedSendTime = json.optString("forwardedSendTime");
			forwardedExternalId = json.optString("forwardedExternalId");
			forwardedOriginal = json.optString("forwardedOriginal");
			forwardedMiddle = json.optString("forwardedMiddle");
			forwardedThumbnail = json.optString("forwardedThumbnail");
		}
	}
}